package com.linkage.lcims.base.dao.cdma.impl;

import java.util.Map;

import com.linkage.lcims.base.dao.HibernateBaseDAOImpl;
import com.linkage.lcims.base.dao.cdma.interfaces.UserDAO;
import com.linkage.lcims.base.po.cdma.CUser;
import com.linkage.util.exception.DAOException;
import com.linkage.util.service.Hash163;

public class UserDAOImpl extends HibernateBaseDAOImpl implements UserDAO {

	private static final String tablePrefix="C_USER";
	
	public void deleteCUser(CUser user) throws DAOException {
		String username=user.getUsername();
		try {
			super.delete(tablePrefix+Hash163.sHash(username), username);
		} catch (Exception e) {
			throw new DAOException(e);
		}
	}

	public CUser getCUser(String username) throws DAOException {
		try {
			return (CUser)super.getByID(tablePrefix+Hash163.sHash(username),username);
		} catch (Exception e) {
			throw new DAOException(e);
		}
	}

	public void saveCUser(CUser user) throws DAOException {
		String username=user.getUsername();
		try {
			super.save(tablePrefix+Hash163.sHash(username), user);
		} catch (Exception e) {
			throw new DAOException(e);
		}
	}

	public void updateCUser(CUser user) throws DAOException {
		String username=user.getUsername();
		try {
			super.merge(tablePrefix+Hash163.sHash(username), user);
		} catch (Exception e) {
			throw new DAOException(e);
		}
	}

	public void updateCUserFileds(String username, Map<String, ?> fields)
			throws DAOException {
		try {
			super.updateEntityField(tablePrefix+Hash163.sHash(username), 
					"com.linkage.lcims.base.po.cdma.CUser", username, fields);
		} catch (Exception e) {
			throw new DAOException(e);
		}
	}
	

}
